package com.itheima.annotation;

import java.lang.reflect.Method;

public class AnnotationDemo3 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException {
        // 1. 获取类对象
        Class c1 = Class.forName("com.itheima.annotation.Student");
        // 2. 判断类是否被注解标注
        if(c1.isAnnotationPresent(MyTest2.class)){
            // 3. 获取注解
            MyTest2 annotation = (MyTest2) c1.getAnnotation(MyTest2.class);
            System.out.println(annotation.name());
            System.out.println(annotation.age());
            System.out.println(annotation.sex());
        }

        System.out.println("----------------------------");
        // 获取方法上的注解
        // 1. 获取方法对象
        Method m = c1.getDeclaredMethod("GetInfo");
        // 2. 判断方法是否被注解标注
        if(m.isAnnotationPresent(MyTest2.class)){
            // 3. 获取注解
            MyTest2 annotation = m.getAnnotation(MyTest2.class);
            System.out.println(annotation.name());
            System.out.println(annotation.age());
            System.out.println(annotation.sex());
        }
    }
}
